package com.molichuxing.services.infrastructure.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.OrderAuditMapper;
import com.molichuxing.services.infrastructure.dto.request.create.OrderAuditCreateDto;
import com.molichuxing.services.infrastructure.dto.response.OrderAuditDto;
import com.molichuxing.services.infrastructure.service.OrderAuditService;
import com.molichuxing.services.property.OrderAuditTypeEnum;

/**
 * 订单审核服务
 * 
 * @author zoumingyu
 * @date 2019年9月27日
 *
 */
@Service("orderAuditService")
public class OrderAuditServiceImpl implements OrderAuditService {

	@Resource
	private OrderAuditMapper orderAuditMapper;

	/**
	 * 新增订单审核信息
	 * 
	 * @param createDto
	 * @return
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
	public int create(OrderAuditCreateDto createDto) {
		return orderAuditMapper.create(Convert.toOrderAuditBean(createDto));
	}

	/**
	 * 查询订单审核信息
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public OrderAuditDto getOrderAudit(Integer id) {
		return Convert.toOrderAuditDto(orderAuditMapper.getById(id));
	}

	/**
	 * 查询订单审核信息
	 * 
	 * @param orderCode
	 *            订单号
	 * @return
	 */
	@Override
	public OrderAuditDto getOrderAudit(Long orderCode) {
		return Convert
				.toOrderAuditDto(orderAuditMapper.getByOrderCode(orderCode, OrderAuditTypeEnum.BUSINESS.getValue()));
	}

	/**
	 * 查询订单审核信息
	 * 
	 * @param orderCode
	 *            订单号
	 * @param type
	 *            类型
	 * @return
	 */
	@Override
	public OrderAuditDto getOrderAudit(Long orderCode, OrderAuditTypeEnum type) {
		return Convert.toOrderAuditDto(orderAuditMapper.getByOrderCode(orderCode, type.getValue()));
	}

}
